﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using ZFSDomain.Interface.User;
using ZFSDomain.ViewModel.Dictionary;

namespace ZFSDomain.ViewDialog.Dictionary
{

    /// <summary>
    /// 数据字典弹窗
    /// </summary>
    public class DictionaryViewDlg : IDictionaryDialog
    {
        /// <summary>
        /// 关联窗口对象
        /// </summary>
        private View.Dictionary.DictionaryViewDialog view;


        /// <summary>
        /// 绑定执行上下文
        /// </summary>
        /// <typeparam name="TViewModel"></typeparam>
        /// <param name="viewModel"></param>
        public void BindViewModel<TViewModel>(TViewModel viewModel) where TViewModel : ViewModelBase
        {
            this.GetDialog().DataContext = viewModel;
        }

        /// <summary>
        /// 关闭窗口
        /// </summary>
        public void Close()
        {
            this.GetDialog().Close();
        }

        /// <summary>
        /// 打开窗口
        /// </summary>
        /// <returns></returns>
        public bool? ShowDialog()
        {
            var dialog = this.GetDialog();
            dialog.ShowDialog();
            return (dialog.DataContext as DictionaryDialogViewModel).Result;
        }

        /// <summary>
        /// 获取窗口实例
        /// </summary>
        /// <returns></returns>
        public View.Dictionary.DictionaryViewDialog GetDialog()
        {
            if (view == null)
            {
                view = new View.Dictionary.DictionaryViewDialog();
            }
            return view;
        }
    }
}
